<#include "/common/taglibs.ftl" />
<meta name="decorator" content="simple"/>
<title><@spring.message code="${entityName!}" /> - <@spring.message code="list" /></title>
<div class="m-portlet">
    <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
            <div class="m-portlet__head-title">
                <h3 class="m-portlet__head-text">
                    <i class="la la-tree"></i> <@spring.message code="${entityName!}" />
                </h3>
            </div>
        </div>
    </div>
    <div class="m-portlet__body">
        <ul class="nav nav-tabs m-tabs-line m-tabs-line--success m-tabs-line--2x" role="tablist">
            <li class="nav-item m-tabs__item">
                <a class="nav-link m-tabs__link ${(!RequestParameters['search_EQ_show']??)?string('active','')}" href="${ctx}/${baseUrl!}/tree?async=true" role="tab">
                    <i title='<@spring.message code="tree.tips.click.to.refresh" />' class="la la-refresh" style="cursor: pointer;"></i>
                        <@spring.message code="tree.tab.all" />
                </a>
            </li>
            <li class="nav-item m-tabs__item">
                <a class="nav-link m-tabs__link ${(RequestParameters['search_EQ_show']??)?string('active','')}" href="${ctx}/${baseUrl!}/tree?async=true&search_EQ_show=true" role="tab">
                    <i title='<@spring.message code="tree.tips.click.to.refresh" />' class="la la-refresh" style="cursor: pointer;"></i>
                        <@spring.message code="tree.tab.show" />
                </a>
            </li>
        </ul>
        <div align="center">
            <button id="expandAll" type="button" class="btn btn-success" ><i class="la la-folder-open"></i>&nbsp;<@spring.message code="tree.btn.expand.all" /></button>
            <@security.authorize access="hasAuthority('${resourceIdentity!}:create')">
            <button type="button" class="btn btn-primary" onclick="toAddRootPage()"><i class="la la-plus-circle"></i>&nbsp;<@spring.message code="tree.btn.add.root.node" /></button>
            </@security.authorize>
        </div>
        <div class="tab-content">
            <div class="tab-pane active">
                <ul id="treeDemo" class="ztree"></ul>
            </div>
        </div>
    </div>
</div>
<page-plugin-style>
<#include "/common/plugins/jquery.ztree.style.ftl" />
</page-plugin-style>
<page-plugin-script>
<#include "/common/plugins/jquery.ztree.script.ftl" />
</page-plugin-script>
<page-style>
</page-style>
<page-script>
    <SCRIPT type="text/javascript" >
    function toAddRootPage(){
		parent.frames['contentFrame'].location.href="${ctx}/${baseUrl!}/create";
	}
	jQuery(function($) {
		var zNodes = ${treesJson};
		$.m.zTree.initMovableTree({
			containerId: "treeDemo",
			expandAllId: "expandAll",
			zNodes : zNodes,
            urlPrefix : "${ctx}/${baseUrl!}",
            async : ${((RequestParameters['async']!)=='true')?string('true','false')},
            //asyncLoadAll : true,
            onlyDisplayShow: ${((RequestParameters['search_EQ_show']!)=='true')?string('true','false')},
            autocomplete : {
	            enable : true
	        },
            permission: <@treePermission resourceIdentity="${resourceIdentity!}"/>,
            setting : {
            	view:{showIcon:true},
                callback : {
                    onClick: function(event, treeId, treeNode, clickFlag) {
                    	var href = '${ctx}/${baseUrl!}/' + treeNode.id;
                        parent.frames['contentFrame'].location.href=href;
                    }
                }
            }
		});
	});

  </SCRIPT>
</page-script>